package leetcode.editor.cn.q1_300.q50;

import java.util.Arrays;

/**
 * @author qidi
 * @date 2021-12-24 09:46:18
 */
class Q0088_MergeSortedArray {

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public void merge(int[] nums1, int m, int[] nums2, int n) {
            int index = nums1.length - 1;

            while (n > 0) {
                nums1[index--] = m > 0 && nums1[m - 1] >= nums2[n - 1] ? nums1[--m] : nums2[--n];
            }
        }
    }
//leetcode submit region end(Prohibit modification and deletion)


    public static void main(String[] args) {
        Solution solution = new Q0088_MergeSortedArray().new Solution();
        int[] arr;
        arr = new int[]{0};
        solution.merge(arr, 0, new int[]{2}, 1);
        System.out.println(Arrays.toString(arr));

        arr = new int[]{2};
        solution.merge(arr, 1, new int[]{}, 0);
        System.out.println(Arrays.toString(arr));

        arr = new int[]{1, 2, 3, 0, 0, 0};
        solution.merge(arr, 3, new int[]{2, 5, 6}, 3);
        System.out.println(Arrays.toString(arr));

        arr = new int[]{7, 8, 9, 0, 0, 0};
        solution.merge(arr, 3, new int[]{2, 5, 6}, 3);
        System.out.println(Arrays.toString(arr));

        arr = new int[]{3, 4, 5, 0, 0, 0};
        solution.merge(arr, 3, new int[]{2, 5, 6}, 3);
        System.out.println(Arrays.toString(arr));
    }
}